#include<vector>
#include<list>
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<set>
#include<queue>
using namespace std;
int main() {
	list<int> l;
	int  sum = 0,max_value = 0;
	
	
	for (int i = 197; i <= 1e7; i++) {
		int num = i;
		l.clear();
		sum = 0;
		while (num) {
			int tmp = num % 10;
			
			l.push_back(tmp);
			num = num / 10;
			sum += tmp;
			
		}
		l.reverse();
		int top = 0;
		while (true) {
		
			//l.pop_front();
			//sum = sum - top;
			
			l.push_back(sum - top);
			 top = l.front();
			 l.pop_front();
			sum += sum - top;
			
			if (i == sum) {
				max_value = i;
				cout << max_value << endl;
				break;
			}
			else if (sum > i) {
				break;
			}
		}
	}
	cout << max_value;

	return 0;
}